Add a function which extracts the filename portion from given full name.
authoroliskoli <oliskoli>
Thu, 7 Dec 2006 19:29:51 +0000 (19:29 +0000)
committeroliskoli <oliskoli>
Thu, 7 Dec 2006 19:29:51 +0000 (19:29 +0000)
defs.h
util.c

diff --git a/defs.h b/defs.h
index 8bb8f16cd50d34f648d4c209fef7ae9277ba7592..ab2024f95b5b9d80f0cc72b997028cd42178ebbf 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -726,6 +726,8 @@ char * convert_human_date_format(const char *human_datef);  /* "MM,YYYY,DD" -> "%
 char * convert_human_time_format(const char *human_timef);     /* "HH+mm+ss"   -> "%H+%M+%S" */
 char * pretty_deg_format(double lat, double lon, char fmt, int html);   /* decimal ->  dd.dddd or dd mm.mmm or dd mm ss */
 
+char * get_filename(const char *fname);                                /* extract the filename portion */
+
 /* 
  * Character encoding transformations.
  */
diff --git a/util.c b/util.c
index 1fabfe0c05b86ae78812c0d6bc6f90dbea91f6bf..c0debfcc864cd4e53e84eb24961067bf5675421f 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1627,3 +1627,17 @@ char *xml_attribute( xml_tag *tag, char *attrname )
        }
        return result;
 }
+
+char *get_filename(const char *fname)
+{
+       char *res, *cb, *cs;
+       
+       cb = strrchr(fname, '\\');
+       cs = strrchr(fname, '/');
+       
+       if (cb == NULL) res = cs;
+       else if (cs == NULL) res = cb;
+       else res = (cs > cb) ? cs : cb;
+       
+       return (res == NULL) ? (char *) fname : ++res;
+}